<?php
session_start();
	require_once("../db_connect.php");
	if(!array_key_exists("user_id",$_SESSION)){
		header("Location: ../top.php");
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="../../js/jquery.corner.js"></script>
<script type="text/javascript">
	var pass_flg=0;
	var mail_flg=0;
	 $(document).ready(function(){

		$('.box').corner();
		$('.box2').corner();
		$('.box3').corner();
		$('.box4').corner();

		 $('#pass').focusout(function(){
			 	if(pass_flg!=0){
					error_check("pass","re_pass","pass_error_check","パスワード");
			 	}
			 	pass_flg=1;
		 });
		 $('#re_pass').focusout(function(){
				error_check("pass","re_pass","pass_error_check","パスワード");
		 });
		 $('#mail').focusout(function(){
			 if(mail_flg!=0){
				error_check("mail","re_mail","mail_error_check","メールアドレス");
			 }
			 mail_flg=1;
		 });
		 $('#re_mail').focusout(function(){
				error_check("mail","re_mail","mail_error_check","メールアドレス");
		 });
	});

	function error_check(a,b,c,d){
		if($("#"+a).val()!=$("#"+b).val()){
			$('#'+c).html(d+"が一致しません");
		}else{
			$('#'+c).html("");
		}
	}
 </script>
<link rel="stylesheet" href="./../../css/css.css" type="text/css" />
<title>会員情報変更</title>
</head>
    <body>
	<div id="container">
		<div id="header" class="box4">
			<div id="header_box" >
				<div id="title">
				</div>
				<div id="search_box">
					<a href="#" id="volunteer">ボランティア</a>｜<a href="#" id="thread">掲示板</a>
					<form method="post" action="../search_function/search_display_free.php?target=volunteer" id="target">
						<input type="text"  name="search_word"><br />
						<input type="submit" value="検索する" id="search_button">
					</form>
				</div>
			</div>
		</div>
		<div id="rightnavi" class="box">
		<?php if(empty($_SESSION["user_name"])&&empty($_SESSION["user_id"])){?>
			<h3>ログインフォーム</h3>
			<form method="post" action="./user_function/UserLogin.php">
				ID：　　<input type="text" name="id" size="10"><br />
				PASS：<input type="text" name="pass" size="10"><br />
				<input style="margin:10px 0 0 39px;" type="image" src="../img/login.png" alt="送信ボタン" name="submit" align="middle">
			</form>
			<a  href="./PHP/User_create.php"><img style="margin:-20px 0 0 39px;" src="../img/newuser.png" border="0"></a>
		<?php }else{?>
				<img src="../../img/kaiinlogo.png" id="kaiinlogo" />
				<p>ようこそ<?php echo $_SESSION['nick_name']?>さん！</p>
				<p><a href="user_infomation.php">会員情報表示</a></p>
				<p><a href="user_update.php">会員情報変更</a></p>
				<p><a href="user_display_application.php">申請中ボランティア</a></p>
				<p><a href="user_display_volunteer.php">提供中ボランティア</a></p>
				<p><a href="../volunteer_function/volunteer_information_insert.php">ボランティア作成</a></p>
				<p><a href="./logout.php">ログアウト</a></p>
				<br />
		<?php }?>
		<img src="../../img/keizilogo.png" id="keizilogo" />
<ul class="menu_margin">
<div id="thread_title_look">
<?php

	//スレッド項目取得
	$sql = "SELECT t.thread_id,count(thread_name) as thread_count,t.thread_name,max(r.response_date) as response_date,t.thread_id FROM thread AS t LEFT OUTER JOIN response AS r ON t.thread_id = r.thread_id group by t.thread_name order by response_date desc limit 0,5";
	$sth = $db->query($sql);
	if (DB::isError($sth)) {
	  exit($sth->getMessage());
	}

	//スレッド表示
	while ($data = $sth->fetchRow(DB_FETCHMODE_ASSOC)) {
	  echo "<li><a href='../response.php?thread_id=".$data['thread_id']."'>";
	  echo mb_strlen($data['thread_name'])>=9?mb_substr($data['thread_name'],0,9)."...":$data['thread_name'];
	  echo "</a></li>";
	}
?>
				</ul>
		<div id="more"><a href="../thread.php" >もっと見る...</a></div>
	</div>
<div id="main"  class="box4">
<form action="UserUpdate.php" method="POST" name="userUpdate" onSubmit="return chValie()" >
<br />
	<h1 align="center">会員情報変更</h1>

	<table id="table-06">
	<?php
	$user_id = $_SESSION['user_id'];

	$sth = "SELECT position_id,position_name,user_id,login_id,family_name,given_name,family_kana,given_kana,nick_name,pref,birth_day,phone_number,gender,password,email,
				   group_name,group_kana,information,url
		FROM user u,position p
		WHERE u.post_id = p.position_id and user_id =?";

	$data = array($user_id);

	$res =& $db->query($sth,$data);
	if (PEAR::isError($res)) {			//SQLの実行に失敗すればここでエラー文を出力
		die($res->getMessage());
	}
	while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {	//SQLの実行結果を表示
	?>

		<b>※個人会員情報</b>
		<tr>
		<th>名前</th><td><input type="text" name="Family_Name"  value="<?php echo $row['family_name'];?>" /><input type="text" name="Given_Name"  style="margin:0 0 0 10px;" value="<?php echo $row['given_name'];?>" /></td>
		</tr>
		<tr>
		<th>フリガナ</th><td><input type="text" name="Family_Kana"  value="<?php echo $row['family_kana'];?>" /><input type="text" name="Given_Kana"  style="margin:0 0 0 10px;" value="<?php echo $row['given_kana'];?>" /></td>
		</tr>
		<tr>
		<th>ニックネーム</th><td><input type="text" name="Nick_Name"  value="<?php echo $row['nick_name'];?>" /></td>
		</tr>
		<tr>
		<th>ログインID</th><td><input type="text" name="Login_Id"  value="<?php echo $row['login_id'];?>" /></td>
		</tr>
		<tr>
		<th>生年月日</th><td><?php
				$birth_day_array = explode("-",$row['birth_day']);
				$year	= $birth_day_array[0];//年
				$month	= $birth_day_array[1];//月
				$day	= $birth_day_array[2];//日

				if (strpos($month,"0") === 0)
				{
					$month = substr($month,1,1);
				}

				if (strpos($day,"0") === 0)
				{
					$day = substr($day,1,1);
				}
?>
			<select name="year" >
			<?php
				//echo "<option>".$birth_day_array[0]."</option>";
				$now = date("Y");
				for($i = 1900; $i<= $now; $i++)
				{
					if ($i == $year)
					{
						echo "<option value='".$year."' selected='selected'>".$year."</option>";
					}
					else
					{
						echo "<option value=".$i.">".$i."</option>";
					}
				}
			?>
			</select>年

			<select name="month">
			<?php
				//echo "<option>".$birth_day_array[1]."</option>";
				$now = date("m");
				for($i = 1; $i<=12; $i++)
				{
					if ($i == $month)
					{
						echo "<option value='".$month."' selected='selected'>".$month."</option>";
					}
					else
					{
						echo "<option value=".$i.">".$i."</option>";
					}
				}
			?>

			</select>月

			 <select name="day">
			<?php
				//echo "<option>".$birth_day_array[2]."</option>";
				$now = date("d");
				for($i = 1; $i<=31; $i++)
				{
					if ($i == $day)
					{
						echo "<option value='".$day."' selected='selected'>".$day."</option>";
					}
					else
					{
						echo "<option value=".$i.">".$i."</option>";
					}
				}
			?>

			</select>日
			</td>
		</tr>
		<tr>
		<th>性別</th><td><select name="Gender">

		<?php if ($row['gender'] == "男") {echo "<option value='".$row['gender']."' selected='selected'>".$row['gender']."</option>";} else {echo "<option value='男'>男</option>";}?>
		<?php if ($row['gender'] == "女") {echo "<option value='".$row['gender']."' selected='selected'>".$row['gender']."</option>";} else {echo "<option value='女'>女</option>";}?>

		</select></td>
		</tr>
		<tr>
		<th>職業</th><td><select name="Position_ID">
		<?php
			if(!isset($_SESSION['tmp_job'])){
				$tmp_array = array();
				$res =& $db->query("select position_name,position_id from position");	//SQLを実行して、結果を $res に代入
				if (PEAR::isError($res)) {			//SQLの実行に失敗すればここでエラー文を出力
					die($res->getMessage());
				}
				while ($res2 =& $res->fetchRow(DB_FETCHMODE_ASSOC)) {	//SQLの実行結果を表示
					$tmp_array+=array($res2['position_id']=>$res2['position_name']);
				}
				$_SESSION['tmp_job']=$tmp_array;
			}

			//echo "<option value=".$row['post_id']." >".$row['position_name']."</option>";
			var_dump($_SESSION['position_id']);
			while( list($key, $val) = each($_SESSION['tmp_job']) ){
				if ($key == $row['position_id'])
				{
					echo "<option value='".$row['position_id']."' selected='selected'>".$row['position_name']."</option>";
				}
				else
				{
					echo "<option value=".$key.">".$val."</option>";
				}
			}
		?>
		</select></td>
		</tr>
		<tr>
		<th>都道府県</th><td><select name="Pref" id="Pref">
		<?php //<option value="<?php echo $row['pref']"><?php echo $row['pref']</option>  ?>
		<?php if ($row['pref'] == "北海道") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='北海道'>北海道</option>";}?>
		<?php if ($row['pref'] == "青森県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='青森県'>青森県</option>";}?>
		<?php if ($row['pref'] == "岩手県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='岩手県'>岩手県</option>";}?>
		<?php if ($row['pref'] == "宮城県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='宮城県'>宮城県</option>";}?>
		<?php if ($row['pref'] == "秋田県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='秋田県'>秋田県</option>";}?>
		<?php if ($row['pref'] == "山形県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='山形県'>山形県</option>";}?>
		<?php if ($row['pref'] == "福島県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='福島県'>福島県</option>";}?>
		<?php if ($row['pref'] == "茨城県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='茨城県'>茨城県</option>";}?>
		<?php if ($row['pref'] == "栃木県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='栃木県'>栃木県</option>";}?>
		<?php if ($row['pref'] == "群馬県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='群馬県'>群馬県</option>";}?>
		<?php if ($row['pref'] == "埼玉県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='埼玉県'>埼玉県</option>";}?>
		<?php if ($row['pref'] == "千葉県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='千葉県'>千葉県</option>";}?>
		<?php if ($row['pref'] == "東京都") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='東京都'>東京都</option>";}?>
		<?php if ($row['pref'] == "神奈川県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='神奈川県'>神奈川県</option>";}?>
		<?php if ($row['pref'] == "新潟県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='新潟県'>新潟県</option>";}?>
		<?php if ($row['pref'] == "富山県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='富山県'>富山県</option>";}?>
		<?php if ($row['pref'] == "石川県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='石川県'>石川県</option>";}?>
		<?php if ($row['pref'] == "福井県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='福井県'>福井県</option>";}?>
		<?php if ($row['pref'] == "山梨県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='山梨県'>山梨県</option>";}?>
		<?php if ($row['pref'] == "長野県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='長野県'>長野県</option>";}?>
		<?php if ($row['pref'] == "岐阜県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='岐阜県'>岐阜県</option>";}?>
		<?php if ($row['pref'] == "静岡県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='静岡県'>静岡県</option>";}?>
		<?php if ($row['pref'] == "愛知県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='愛知県'>愛知県</option>";}?>
		<?php if ($row['pref'] == "三重県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='三重県'>三重県</option>";}?>
		<?php if ($row['pref'] == "滋賀県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='滋賀県'>滋賀県</option>";}?>
		<?php if ($row['pref'] == "京都府") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='京都府'>京都府</option>";}?>
		<?php if ($row['pref'] == "大阪府") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='大阪府'>大阪府</option>";}?>
		<?php if ($row['pref'] == "兵庫県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='兵庫県'>兵庫県</option>";}?>
		<?php if ($row['pref'] == "奈良県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='奈良県'>奈良県</option>";}?>
		<?php if ($row['pref'] == "和歌山県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='和歌山県'>和歌山県</option>";}?>
		<?php if ($row['pref'] == "鳥取県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='鳥取県'>鳥取県</option>";}?>
		<?php if ($row['pref'] == "島根県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='島根県'>島根県</option>";}?>
		<?php if ($row['pref'] == "岡山県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='岡山県'>岡山県</option>";}?>
		<?php if ($row['pref'] == "広島県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='広島県'>広島県</option>";}?>
		<?php if ($row['pref'] == "山口県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='山口県'>山口県</option>";}?>
		<?php if ($row['pref'] == "徳島県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='徳島県'>徳島県</option>";}?>
		<?php if ($row['pref'] == "香川県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='香川県'>香川県</option>";}?>
		<?php if ($row['pref'] == "愛媛県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='愛媛県'>愛媛県</option>";}?>
		<?php if ($row['pref'] == "高知県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='高知県'>高知県</option>";}?>
		<?php if ($row['pref'] == "福岡県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='福岡県'>福岡県</option>";}?>
		<?php if ($row['pref'] == "佐賀県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='佐賀県'>佐賀県</option>";}?>
		<?php if ($row['pref'] == "長崎県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='長崎県'>長崎県</option>";}?>
		<?php if ($row['pref'] == "熊本県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='熊本県'>熊本県</option>";}?>
		<?php if ($row['pref'] == "大分県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='大分県'>大分県</option>";}?>
		<?php if ($row['pref'] == "宮崎県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='宮崎県'>宮崎県</option>";}?>
		<?php if ($row['pref'] == "鹿児島県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='鹿児島県'>鹿児島県</option>";}?>
		<?php if ($row['pref'] == "沖縄県") {echo "<option value='".$row['pref']."' selected='selected'>".$row['pref']."</option>";} else {echo "<option value='沖縄県'>沖縄県</option>";}?>

<?php /*	<option value="北海道">北海道</option>
		<option value="青森県">青森県</option>
		<option value="岩手県">岩手県</option>
		<option value="宮城県">宮城県</option>
		<option value="秋田県">秋田県</option>
		<option value="山形県">山形県</option>
		<option value="福島県">福島県</option>
		<option value="茨城県">茨城県</option>
		<option value="栃木県">栃木県</option>
		<option value="群馬県">群馬県</option>
		<option value="埼玉県">埼玉県</option>
		<option value="千葉県">千葉県</option>
		<option value="東京都">東京都</option>
		<option value="神奈川県">神奈川県</option>
		<option value="新潟県">新潟県</option>
		<option value="富山県">富山県</option>
		<option value="石川県">石川県</option>
		<option value="福井県">福井県</option>
		<option value="山梨県">山梨県</option>
		<option value="長野県">長野県</option>
		<option value="岐阜県">岐阜県</option>
		<option value="静岡県">静岡県</option>
		<option value="愛知県">愛知県</option>
		<option value="三重県">三重県</option>
		<option value="滋賀県">滋賀県</option>
		<option value="京都府">京都府</option>
		<option value="大阪府">大阪府</option>
		<option value="兵庫県">兵庫県</option>
		<option value="奈良県">奈良県</option>
		<option value="和歌山県">和歌山県</option>
		<option value="鳥取県">鳥取県</option>
		<option value="島根県">島根県</option>
		<option value="岡山県">岡山県</option>
		<option value="広島県">広島県</option>
		<option value="山口県">山口県</option>
		<option value="徳島県">徳島県</option>
		<option value="香川県">香川県</option>
		<option value="愛媛県">愛媛県</option>
		<option value="高知県">高知県</option>
		<option value="福岡県">福岡県</option>
		<option value="佐賀県">佐賀県</option>
		<option value="長崎県">長崎県</option>
		<option value="熊本県">熊本県</option>
		<option value="大分県">大分県</option>
		<option value="宮崎県">宮崎県</option>
		<option value="鹿児島県">鹿児島県</option>
		<option value="沖縄県">沖縄県</option>
*/?>
	</select></td>
			</tr>
			<tr>
		<th>電話番号</th><td><input type="text" name="Phone_Number"  value="<?php echo $row['phone_number'];?>" /></td>
		</tr>
		<tr>
		<th>メールアドレス</th><td><input type="text" name="email"  value="<?php echo $row['email'];?>" /></td>
		</tr>
	</table>
	<table id=table-06>
		<b>※団体会員情報</b>
		<tr>
		<th>団体名</th><td><input type="text" name="group_name"  value="<?php echo $row['group_name'];?>" /></td>
		</tr>
		<tr>
		<th>フリガナ</th><td><input type="text" name="group_kana"  value="<?php echo $row['group_kana'];?>" /></td>
		</tr>
		<tr>
		<th>団体紹介文</th><td><input type="text" name="information"  value="<?php echo $row['information'];?>" /></td>
		</tr>
		<tr>
		<th>団体URL</th><td><input type="text" name="url"  value="<?php echo $row['url'];?>" /></td>
		</tr>
		<tr>
		<th>団体分類</th><td>
		<select name="group_id" id="group_id">
		<option value="">―</option>
		<?php
			if(!isset($_SESSION['tmp_group']))
			{
				$tmp_array = array();
				$res =& $db->query("SELECT * FROM `group`");

				if (PEAR::isError($res))
				{
				die($res->getMessage());
				}
				while ($row =& $res->fetchRow(DB_FETCHMODE_ASSOC))
				{
					$tmp_array+=array($row['group_id']=>$row['group_name']);
				}
				$_SESSION['tmp_group']=$tmp_array;
				}

			while( list($key, $val) = each($_SESSION['tmp_group']))
			{
				echo "<option value=".$key.">".$val."</option>";
			}
			?>
			</select></td>
			</tr>
	</table>
<?php }//131行目のwhile終了
?>
<p>
						<center>
							<input type="submit" value="登録"  style="WIDTH: 70px; HEIGHT: 30px"/>
							　　　　　
							<input type="reset" value="リセット"   style="WIDTH: 70px; HEIGHT: 30px"/>
						</center>
					</p></form>
</div>
<div id="space"></div>
		</div>
    </body>
</html>